a11y: Set an accessible role for GtkWindow
authorMatthias Clasen <mclasen@redhat.com>
Mon, 27 Jul 2020 22:25:37 +0000 (18:25 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 28 Jul 2020 01:18:10 +0000 (21:18 -0400)
Use the window accessible role for GtkWindow, and
set the modal accessible property.

docs/reference/gtk/section-accessibility.md
gtk/gtkenums.h
gtk/gtkwindow.c

index c8f2b5983f1bef050d7f0a331c5025aa026eeb62..f640c962b0c943055d55e954244c4d339dc8d4f3 100644 (file)
@@ -57,6 +57,7 @@ Each role name is part of the #GtkAccessibleRole enumeration.
 | `SEPARATOR` | A divider that separates sections of content or groups of items | #GtkSeparator |
 | `SPIN_BUTTON` | A range control that allows seelcting among discrete choices | #GtkSpinButton |
 | `SWITCH` | A control that represents on/off values | #GtkSwitch |
+| `WINDOW` | An application window | #GtkWindow |
 | `...` | … |
 
 See the [WAI-ARIA](https://www.w3.org/WAI/PF/aria/appendices#quickref) list
index 83fb4c645e9249bbd17b6962768a6a50626d3c07..436d2ac39d4cba82a79d08142b19b9f8cf1a07e1 100644 (file)
@@ -1245,7 +1245,7 @@ typedef enum {
  * @GTK_ACCESSIBLE_ROLE_TREE_ITEM: Unused
  * @GTK_ACCESSIBLE_ROLE_WIDGET: An interactive component of a graphical user
  *    interface. This is the role that GTK uses by default for widgets.
- * @GTK_ACCESSIBLE_ROLE_WINDOW: Unused
+ * @GTK_ACCESSIBLE_ROLE_WINDOW: An application window.
  *
  * The accessible role for a #GtkAccessible implementation.
  *
index a0fdd39229f8016a31259765ff30aeae6a934372..067032a07f2173b307232f789e979e0c458a1d63 100644 (file)
  *
  * GtkWindow adds the .titlebar and .default-decoration style classes to the
  * widget that is added as a titlebar child.
+ *
+ * # Accessibility
+ *
+ * GtkWindow uses the #GTK_ACCESSIBLE_ROLE_WINDOW role.
  */
 
 #define MENU_BAR_ACCEL GDK_KEY_F10
@@ -1114,6 +1118,8 @@ gtk_window_class_init (GtkWindowClass *klass)
   add_tab_bindings (widget_class, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
 
   gtk_widget_class_set_css_name (widget_class, I_("window"));
+
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_WINDOW);
 }
 
 /**
@@ -2208,19 +2214,17 @@ gtk_window_real_activate_default (GtkWindow *window)
  * gtk_window_set_modal:
  * @window: a #GtkWindow
  * @modal: whether the window is modal
- * 
+ *
  * Sets a window modal or non-modal. Modal windows prevent interaction
  * with other windows in the same application. To keep modal dialogs
  * on top of main application windows, use
  * gtk_window_set_transient_for() to make the dialog transient for the
  * parent; most [window managers][gtk-X11-arch]
  * will then disallow lowering the dialog below the parent.
- * 
- * 
  **/
 void
 gtk_window_set_modal (GtkWindow *window,
-                     gboolean   modal)
+                      gboolean   modal)
 {
   GtkWindowPrivate *priv = gtk_window_get_instance_private (window);
   GtkWidget *widget;
@@ -2233,20 +2237,24 @@ gtk_window_set_modal (GtkWindow *window,
 
   priv->modal = modal;
   widget = GTK_WIDGET (window);
-  
+
   if (_gtk_widget_get_realized (widget))
     gdk_toplevel_set_modal (GDK_TOPLEVEL (priv->surface), modal);
 
   if (gtk_widget_get_visible (widget))
     {
       if (priv->modal)
-       gtk_grab_add (widget);
+        gtk_grab_add (widget);
       else
-       gtk_grab_remove (widget);
+        gtk_grab_remove (widget);
     }
 
   update_window_actions (window);
 
+  gtk_accessible_update_property (GTK_ACCESSIBLE (window),
+                                  GTK_ACCESSIBLE_PROPERTY_MODAL, modal,
+                                  -1);
+
   g_object_notify_by_pspec (G_OBJECT (window), window_props[PROP_MODAL]);
 }